package com.abe.albumsim;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.permissionx.guolindev.PermissionX;
import com.permissionx.guolindev.callback.ExplainReasonCallback;
import com.permissionx.guolindev.callback.RequestCallback;
import com.permissionx.guolindev.request.ExplainScope;
import com.yanzhenjie.album.sample.AlbumMainActivity;

import java.util.List;

@SuppressLint("InlinedApi")
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //EdgeToEdge.enable(this);
        setContentView(R.layout.act_sim_main);
        findViewById(R.id.btn).setOnClickListener(v -> {
            String[] reqPermissions;
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
                reqPermissions = new String[]{Manifest.permission.READ_MEDIA_IMAGES, Manifest.permission.READ_MEDIA_VIDEO};
            } else {
                reqPermissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
            }
            PermissionX
                    .init(MainActivity.this)
                    .permissions(reqPermissions)
                    .onExplainRequestReason((scope, deniedList) -> scope.showRequestReasonDialog(
                            deniedList, "应用安装需要您同意安装权限才能正常使用", "同意", "拒绝"
                    )).request((allGranted, grantedList, deniedList) -> {
                        System.out.println("deniedList:" + deniedList.size());
                        if (allGranted) {
                            startActivity(new Intent(MainActivity.this, AlbumMainActivity.class));
                        }
                    });
        });
    }
}